﻿using System.Linq;
using QSASPMVCApplicationCSharp.Data;
using ValidationFramework;

namespace QSASPMVCApplicationCSharp
{
	public class CustomValidationMethods
	{
		public static void RequireUniqueProductId(object sender, CustomValidationEventArgs e)
		{
			var productRepository = new SessionProductRepository();
			var matchingProducts = productRepository
				.GetProducts()
				.Where(x => x.ProductName == e.TargetMemberValue)
				.ToArray();

			e.IsValid = matchingProducts.Length <= 0;
		}
	}
}
